/**
 * @USER: Administrator
 * @DATE: 2024/9/17 下午8:36
 * @VERSION: 1.0.0
 */
public class LC883 {
    public static void main(String[] args) {
        LC883 lc883 = new LC883();
        System.out.println(lc883.projectionArea(new int[][]{{1,2},{3,4}}));
    }

    public int projectionArea(int[][] grid) {
        int downArea = 0;

        // 每行取最大值，再求和
        int leftArea = 0;

        // 每列取最大值，再求和
        int backArea = 0;


        for (int i = 0; i < grid[0].length; i++) {
            int columnMax = grid[0][i];
            for (int j = 0; j < grid.length; j++) {
                if (grid[j][i] >columnMax) {
                    columnMax = grid[j][i];
                }
            }
            leftArea+=columnMax;
        }

        for (int[] ints : grid) {
            // 每列的最大值
            int rowMax = ints[0];
            for (int anInt : ints) {
                if (anInt != 0) {
                    downArea++;
                }
                if (anInt > rowMax) {
                    rowMax = anInt;
                }
            }
            leftArea += rowMax;
        }

        return downArea + leftArea + backArea;
    }

}
